<?php
namespace app\admin\validate;
use think\facade\Db;
use think\Validate;

class Contact extends Validate
{

    protected $rule=[
        'id'    =>'require',
        'name'    =>'require',
        'mobile'    =>'require|checkmobile',
        'content'    =>'require',
    ];
    protected $message = [
        'id.require'    => '关键参数不能为空',
        'name.require'    => '姓名不能为空',
        'mobile.require'    => '手机号码不能为空',
        'mobile.unique'    => '已存在相同手机号',
        'content.require'    => '请输入您要对我们说的话',
    ];
    protected $scene = [
        'add' =>['name','mobile','content'],
        'edit'=>['id','name'],
        'del' =>['id'],
    ];

    protected function checkmobile($value,$rule,$data){
        if(!is_numeric($value)){
            return '请输入数字';
        }
        if(strlen($value) != 11){
            return '请输入11位手机号';
        }
        if (!preg_match("/^1[3456789]\d{9}$/", $value)) {
            return '手机号码格式不正确';
        }
        return true;
    }

}